package com.base.string;

/**
 * 434. Number of Segments in a String
 *
 * You are given a string s, return the number of segments in the string. 
 *
 * A segment is defined to be a contiguous sequence of non-space characters.
 *
 * 来源：力扣（LeetCode）
 * 链接：https://leetcode-cn.com/problems/number-of-segments-in-a-string
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
 *
 * @author leon
 * @date 2021年10月07日 17:49
 */
public class CountSegments {
    public int countSegments(String s) {
        if(s== null||s.length()==0){
            return 0;
        }
        String[] ss = s.split(" ");
        int ans = 0;
        for(String st:ss){
            if(st.length()>0){
                ans++;
            }
        }
        return ans;
    }
}
